package com.yc.http.tomcat.impl;

import com.yc.http.tomcat.Cookie;

public class CookieImpl implements Cookie {
    private String domain;
    private Integer maxAge;
    private String path;
    private String name;
    private String value;

    public CookieImpl(String name, String value) {
        this.name = name;
        this.value = value;
    }

    @Override
    public void setDomain(String pattern) {
        this.domain = pattern;
    }

    @Override
    public void setMaxAge(int expiry) {
        this.maxAge = expiry;
    }

    @Override
    public void setPath(String uri) {
        this.path = uri;
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public String getValue() {
        return this.value;
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("Set-Cookie: "+name + "=" + value);
        if (maxAge != null) {
            stringBuilder.append("; Max-Age=" + maxAge);
        }
        if (path != null) {
            stringBuilder.append("; Path=" + path);
        }
        if (domain != null) {
            stringBuilder.append("; Domain=" + domain);
        }
        stringBuilder.append("\n");
        return stringBuilder.toString();
    }
}
